<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">沥青混合料理论最大相对密度试验检测记录<br />(真空法)</div>
        <div class="codeText">
          <tr>
            JGLQ11004a
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span v-if="isPdf" class="placeholder">{{ form.jilbh }}</span>
          <el-input class="code-input" v-else type="text" v-model="form.jilbh" @focus="handleFocus('jilbh')" />
        </div>
      </div>
      <div class="table-border">
        <!-- .........................1111111111111111111111111111111......................................................... -->
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>

            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" style="width: 15%" />%RH
              </td>
            </tr>

            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
            <tr height="25">
              <td>沥青种类及牌号</td>
              <td colspan="5"><el-input type="text" v-model="form.liqzljph" @change="handleInput" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" /></td>
              <td colspan="2">沥青比重</td>
              <td colspan="4"><el-input type="number" v-model="form.liqbz" @change="handleInput" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" /></td>
            </tr>
            <tr height="25">
              <td>拌和温度(℃)</td>
              <td colspan="5"><el-input type="number" v-model="form.banhwd" @change="handleInput" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" /></td>
              <td colspan="2">混合料类型</td>
              <td colspan="4"><el-input type="text" v-model="form.hunhllx" @change="handleInput" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" /></td>
            </tr>
            <tr height="25">
              <td>25℃时水的密度(g/cm³)</td>
              <td colspan="11"><el-input type="number" v-model="form.shuidmd" @change="handleInput" disabled /></td>
            </tr>
            <tr height="25">
              <td width="15%">负压容器类型</td>
              <td width="15%">试验次数</td>
              <td width="7%"><el-input type="number" v-model="form.detailList[0].shiycs" @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[1].shiycs" @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[2].shiycs" @keydown.native="handleKeyDown($event, 2, 2)" :ref="'2_2'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[3].shiycs" @keydown.native="handleKeyDown($event, 2, 3)" :ref="'2_3'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[4].shiycs" @keydown.native="handleKeyDown($event, 2, 4)" :ref="'2_4'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[5].shiycs" @keydown.native="handleKeyDown($event, 2, 5)" :ref="'2_5'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[6].shiycs" @keydown.native="handleKeyDown($event, 2, 6)" :ref="'2_6'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[7].shiycs" @keydown.native="handleKeyDown($event, 2, 7)" :ref="'2_7'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[8].shiycs" @keydown.native="handleKeyDown($event, 2, 8)" :ref="'2_8'" /></td>
              <td width="7%"><el-input type="number" v-model="form.detailList[9].shiycs" @keydown.native="handleKeyDown($event, 2, 9)" :ref="'2_9'" /></td>
            </tr>
            <tr height="25">
              <td rowspan="6">B/C类</td>
              <td>干燥沥青混合料试样的空气中质量(g)</td>
              <td><el-input type="number" v-model="form.detailList[0].kongqzzl" @change="countZdxdmd(0)" @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'" /></td>
              <td><el-input type="number" v-model="form.detailList[1].kongqzzl" @change="countZdxdmd(1)" @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'" /></td>
              <td><el-input type="number" v-model="form.detailList[2].kongqzzl" @change="countZdxdmd(2)" @keydown.native="handleKeyDown($event, 3, 2)" :ref="'3_2'" /></td>
              <td><el-input type="number" v-model="form.detailList[3].kongqzzl" @change="countZdxdmd(3)" @keydown.native="handleKeyDown($event, 3, 3)" :ref="'3_3'" /></td>
              <td><el-input type="number" v-model="form.detailList[4].kongqzzl" @change="countZdxdmd(4)" @keydown.native="handleKeyDown($event, 3, 4)" :ref="'3_4'" /></td>
              <td><el-input type="number" v-model="form.detailList[5].kongqzzl" @change="countZdxdmd(5)" @keydown.native="handleKeyDown($event, 3, 5)" :ref="'3_5'" /></td>
              <td><el-input type="number" v-model="form.detailList[6].kongqzzl" @change="countZdxdmd(6)" @keydown.native="handleKeyDown($event, 3, 6)" :ref="'3_6'" /></td>
              <td><el-input type="number" v-model="form.detailList[7].kongqzzl" @change="countZdxdmd(7)" @keydown.native="handleKeyDown($event, 3, 7)" :ref="'3_7'" /></td>
              <td><el-input type="number" v-model="form.detailList[8].kongqzzl" @change="countZdxdmd(8)" @keydown.native="handleKeyDown($event, 3, 8)" :ref="'3_8'" /></td>
              <td><el-input type="number" v-model="form.detailList[9].kongqzzl" @change="countZdxdmd(9)" @keydown.native="handleKeyDown($event, 3, 9)" :ref="'3_9'" /></td>
            </tr>
            <tr height="25">
              <td>装满25℃水时的负压容器质量(g)</td>
              <td><el-input type="number" v-model="form.detailList[0].rongqzl" @change="countZdxdmd(0)" @keydown.native="handleKeyDown($event, 4, 0)" :ref="'4_0'" /></td>
              <td><el-input type="number" v-model="form.detailList[1].rongqzl" @change="countZdxdmd(1)" @keydown.native="handleKeyDown($event, 4, 1)" :ref="'4_1'" /></td>
              <td><el-input type="number" v-model="form.detailList[2].rongqzl" @change="countZdxdmd(2)" @keydown.native="handleKeyDown($event, 4, 2)" :ref="'4_2'" /></td>
              <td><el-input type="number" v-model="form.detailList[3].rongqzl" @change="countZdxdmd(3)" @keydown.native="handleKeyDown($event, 4, 3)" :ref="'4_3'" /></td>
              <td><el-input type="number" v-model="form.detailList[4].rongqzl" @change="countZdxdmd(4)" @keydown.native="handleKeyDown($event, 4, 4)" :ref="'4_4'" /></td>
              <td><el-input type="number" v-model="form.detailList[5].rongqzl" @change="countZdxdmd(5)" @keydown.native="handleKeyDown($event, 4, 5)" :ref="'4_5'" /></td>
              <td><el-input type="number" v-model="form.detailList[6].rongqzl" @change="countZdxdmd(6)" @keydown.native="handleKeyDown($event, 4, 6)" :ref="'4_6'" /></td>
              <td><el-input type="number" v-model="form.detailList[7].rongqzl" @change="countZdxdmd(7)" @keydown.native="handleKeyDown($event, 4, 7)" :ref="'4_7'" /></td>
              <td><el-input type="number" v-model="form.detailList[8].rongqzl" @change="countZdxdmd(8)" @keydown.native="handleKeyDown($event, 4, 8)" :ref="'4_8'" /></td>
              <td><el-input type="number" v-model="form.detailList[9].rongqzl" @change="countZdxdmd(9)" @keydown.native="handleKeyDown($event, 4, 9)" :ref="'4_9'" /></td>
            </tr>
            <tr height="25">
              <td>25℃时试样水与负压容器的总质量(g)</td>
              <td><el-input type="number" v-model="form.detailList[0].rongqdzzl" @change="countZdxdmd(0)" @keydown.native="handleKeyDown($event, 5, 0)" :ref="'5_0'" /></td>
              <td><el-input type="number" v-model="form.detailList[1].rongqdzzl" @change="countZdxdmd(1)" @keydown.native="handleKeyDown($event, 5, 1)" :ref="'5_1'" /></td>
              <td><el-input type="number" v-model="form.detailList[2].rongqdzzl" @change="countZdxdmd(2)" @keydown.native="handleKeyDown($event, 5, 2)" :ref="'5_2'" /></td>
              <td><el-input type="number" v-model="form.detailList[3].rongqdzzl" @change="countZdxdmd(3)" @keydown.native="handleKeyDown($event, 5, 3)" :ref="'5_3'" /></td>
              <td><el-input type="number" v-model="form.detailList[4].rongqdzzl" @change="countZdxdmd(4)" @keydown.native="handleKeyDown($event, 5, 4)" :ref="'5_4'" /></td>
              <td><el-input type="number" v-model="form.detailList[5].rongqdzzl" @change="countZdxdmd(5)" @keydown.native="handleKeyDown($event, 5, 5)" :ref="'5_5'" /></td>
              <td><el-input type="number" v-model="form.detailList[6].rongqdzzl" @change="countZdxdmd(6)" @keydown.native="handleKeyDown($event, 5, 6)" :ref="'5_6'" /></td>
              <td><el-input type="number" v-model="form.detailList[7].rongqdzzl" @change="countZdxdmd(7)" @keydown.native="handleKeyDown($event, 5, 7)" :ref="'5_7'" /></td>
              <td><el-input type="number" v-model="form.detailList[8].rongqdzzl" @change="countZdxdmd(8)" @keydown.native="handleKeyDown($event, 5, 8)" :ref="'5_8'" /></td>
              <td><el-input type="number" v-model="form.detailList[9].rongqdzzl" @change="countZdxdmd(9)" @keydown.native="handleKeyDown($event, 5, 9)" :ref="'5_9'" /></td>
            </tr>
            <tr height="25">
              <td>沥青混合料理论最大相对密度(g)</td>
              <td><el-input type="number" v-model="form.detailList[0].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[1].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[2].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[3].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[4].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[5].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[6].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[7].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[8].xiangdmd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[9].xiangdmd" disabled /></td>
            </tr>
            <tr height="25">
              <td>平均值</td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[0].pingjz" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[2].pingjz" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[4].pingjz" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[6].pingjz" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[8].pingjz" disabled /></td>
            </tr>
            <tr height="25">
              <td>沥青混合料理论最大密度(g/cm³)</td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[0].lilzdmd" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[2].lilzdmd" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[4].lilzdmd" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[6].lilzdmd" disabled /></td>
              <td colspan="2"><el-input type="number" v-model="form.detailList[8].lilzdmd" disabled /></td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { listLqhhlLlzdxdmdjlbBsInfo, getLqhhlLlzdxdmdjlbBsInfo, delLqhhlLlzdxdmdjlbBsInfo, addLqhhlLlzdxdmdjlbBsInfo, updateLqhhlLlzdxdmdjlbBsInfo } from "@/api/report_lqhhl/lqhhlLlzdxdmdjlbBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BaQjDetailView from "@/views/sycs/baQjDetail/BaQjDetailView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

import decimal from "@/utils/big-decimal";
import { handleFocus, emptyConvert, calculateMeanvalue, handleKeyDown } from "@/views/reportForms/utils";
import Bus from "@/utils/bus";
export default {
  name: "lqhhlllzdxdmdjlb",
  components: {
    BsInstrumentView,
    BaQjDetailView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      params: {},
      query: {},
      // 表单参数
      form: {
        detailList: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
      }
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created() {
    this.getInfo();
  },
  methods: {
    // 获取详情
    getInfo() {
      getLqhhlLlzdxdmdjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        this.form.shuidmd = 0.9971;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setLqhhlLlzdxdmdBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setLqhhlLlzdxdmdBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },

    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    submitForm() {
      return this.form;
    },
    countZdxdmd(num) {
      let a = Number(this.form.detailList[num].kongqzzl);
      let b = Number(this.form.detailList[num].rongqzl);
      let c = Number(this.form.detailList[num].rongqdzzl);
      if (a && b && c) {
        let data = a / (a + b - c);
        this.form.detailList[num].xiangdmd = decimal.round(data, 3);
        let numKey = {
          0: [0, 1],
          1: [0, 1],
          2: [2, 3],
          3: [2, 3],
          4: [4, 5],
          5: [4, 5],
          6: [6, 7],
          7: [6, 7],
          8: [8, 9],
          9: [8, 9]
        };
        let numKeyNum = {
          0: 0,
          1: 0,
          2: 2,
          3: 2,
          4: 4,
          5: 4,
          6: 6,
          7: 6,
          8: 8,
          9: 8
        };
        this.countPjz(numKeyNum[num], numKey[num]);
      }
    },
    countPjz(num, arr) {
      let A1 = this.form.detailList[arr[0]].xiangdmd;
      let A2 = this.form.detailList[arr[1]].xiangdmd;
      if (A1 && A2) {
        let X = calculateMeanvalue([A1, A2], 3);
        this.form.detailList[num].pingjz = X;
        this.form.detailList[num].lilzdmd = decimal.round(X * 0.9971, 3);
        this.handleInput();
      }
    },
    handleInput() {
      Bus.$emit("setLqhhlLlzdxdmdBg", {
        key: 153,
        liqzljph: this.form.liqzljph,
        liqbz: this.form.liqbz,
        banhwd: this.form.banhwd,
        hunhllx: this.form.hunhllx,
        shuidmd: this.form.shuidmd,
        lilzdmdArr: [this.form.detailList[0].lilzdmd, this.form.detailList[2].lilzdmd, this.form.detailList[4].lilzdmd, this.form.detailList[6].lilzdmd, this.form.detailList[8].lilzdmd]
      });
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [1, 1, 9, 9, 9, 9];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped>
</style>
